// pages/fork/index/index.js
const appInstance = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        forkData:{
            type:Object,
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        imgUrl:"https://img.yzcdn.cn/vant/cat.jpeg",
        activeKey:0,
        goodlist:[],
        active:1
    },

    /**
     * 组件的方法列表
     */
    methods: {
        godetail(event){
            console.log(event)
            let goodId = event.currentTarget.dataset.goodid
            wx.navigateTo({
                url: '/pages/common/gooddetail/gooddetail?id=' + goodId,
            })
        },
        getgoodlist(categoryid){
            let that = this;
            let base = appInstance.globalData.base_url;
            wx.request({
                url: base + '/goods/?category=' + categoryid + "&limit=50",
                success(res){
                    console.log(res.data)
                    if (res.data.results.length>0){
                        that.setData({ goodlist: res.data.results })
                    }else{
                        wx.showToast({
                            title: '暂无数据',
                        });
                        that.setData({ goodlist: [] })
                    }
                }
            })
        },
        onClick(event) {
            //console.log(event.detail.name)
            let that = this;
            let categoryId = event.detail.name;
            this.getgoodlist(categoryId)
        },
    },
    ready(){
        this.getgoodlist(1);
    }
})
